
<?php
$id = $_POST['id']; If ($id == "_empty" || $_POST['oper'] =='new') $new = 1;  //echo $id;
if ($_POST['title']) $fields .= "title='" . $_POST['title']."', ";
if ($_POST['text']) $fields .= "text='" . $_POST['text']."', ";  
if ($_POST['type']) $fields .= "type='" . $_POST['type']."', "; 
if ($_POST['status']) $fields .= "status='" . $_POST['status']."', ";

if ($_POST['status']) $fields .= "start_date='" . $_POST['start_date']."', "; 
if ($_POST['status']) $fields .= "end_date='" . $_POST['end_date']."', ";
if ($_POST['status']) $fields .= "track_number='" . $_POST['track_number']."', ";



$fields = rtrim($fields, ', ');

// connect to the database
include "../../includes/functions.php";

echo db_connect(); 
 
 if ($_POST['oper'] =='del') {
	$result = mysql_query('DELETE FROM sponsorship_spots WHERE `id` = "'.$id.'"');
	if (!$result) { echo "error deleting record on server side.";}
	exit;	
}
 
 
if ($new) {
	$SQL = "INSERT INTO sponsorship_spots (id, title, `text`, type, status, start_date, end_date, track_number) VALUES ('','".$_POST['title']."','".$_POST['text']."','".$_POST['type']."','".$_POST['status']."','".$_POST['start_date']."','".$_POST['end_date']."','".$_POST['track_number']."')"; echo $SQL;
} else {
	$SQL = "UPDATE sponsorship_spots SET $fields WHERE id = '$id'"; //echo $SQL;
}

$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());


?>	
